#######################
# calculating uk enpp #
#######################


### uk enpp

uk_seat<-read.csv("uk_seatshare.csv")
attach(uk_seat)
uk_seat$perseat=absseat/totseats
uk_seat$perseat_sq=uk_seat$perseat^2
uk_seat<-na.omit(uk_seat)


##calculate two types of ENPP

#molinar
tb_enpp_np<-
  uk_seat %>%group_by(edate) %>%
  summarise(enpp_np=1+(1/(sum(perseat^2))*
  ((sum(perseat^2)-max(perseat^2))/sum(perseat^2))))

#laakso
tb_enpp<-uk_seat %>%group_by(edate) %>%
  summarise(enpp=1/sum(perseat^2))

#setting dataset
enpp_uk<-data.frame(tb_enpp_np,tb_enpp)

#output .csv
write.csv(enpp_uk,"enpp_uk.csv")